# -*- coding: utf-8 -*-
import json
import time
def recursive_parse(data):
    if isinstance(data, dict):
        new_dict = {}
        for key, value in data.items():
            try:
                # 尝试将值解析为 JSON
                parsed_value = json.loads(value)
                # 递归解析解析后的值
                new_dict[key] = recursive_parse(parsed_value)
            except (json.JSONDecodeError, TypeError):
                # 如果解析失败，说明不是 JSON 字符串，直接使用原数据
                new_dict[key] = recursive_parse(value)
        return new_dict
    elif isinstance(data, list):
        # 处理列表
        return [recursive_parse(item) for item in data]
    else:
        # 其他类型（如字符串、数字等）直接返回
        return data
case_id = "123"
payload = {
        "case_id": case_id,
        "hot_blood_time": "1",
        "bianyuan_organ_id": "[\"1\",\"2\",\"3\",\"4\",\"5\",\"6\"]",
        "bianyuan_organ": "[\"肾脏\",\"肝脏\",\"心脏\",\"肺脏\",\"角膜\",\"胰腺\"]",
        "organ_donate_case_record_json": "{\"gender\":\"男\",\"age\":\"27\",\"birth\":\"1997-04-12\",\"ethnicOption\":\"回族\",\"nativePlace\":[\"陕西省\",\"西安市\",\"长安区\"],\"nationality\":\"中国\",\"marriage\":\"未婚\",\"career\":\"无\",\"postalCode\":\"1\",\"choseIdenType\":\"身份证号\",\"workUnit\":\"1\",\"hospitalization\":\"否\",\"spHosp\":\"\",\"vaccination\":\"否\",\"relationP\":[\"父\"],\"relationC\":[],\"sun\":\"\",\"daughter\":\"\",\"brother\":\"\",\"sister\":\"\",\"contact\":\"1\",\"contactRela\":\"1\",\"contactPhone\":\"1\",\"contactAddr\":\"1\",\"dateToHos\":\"2024-12-04T06:51:10.977Z\",\"dateToOffice\":\"2024-12-11T06:51:12.902Z\",\"dateToWrite\":\"2024-12-03T06:51:14.073Z\",\"primaryDisease\":\"1\",\"primaryDiseaseDate\":\"2024-12-04T06:51:17.167Z\",\"coma\":\"深昏迷\",\"breath\":\"有\",\"breathMachine\":\"否\",\"reflex\":\"有\",\"hypertension\":\"无\",\"hypertensionYear\":\"\",\"cardiopathy\":\"无\",\"cardiopathyYear\":\"\",\"diabetes\":\"无\",\"diabetesYear\":\"\",\"Cerebrovascular\":\"无\",\"CerebrovascularDiag\":\"\",\"CerebrovascularYear\":\"\",\"tumour\":\"无\",\"liverFailure\":\"无\",\"kidneyFailure\":\"无\",\"smokingHis\":\"无\",\"drinkingHis\":\"无\",\"operationHis\":\"无\",\"operation\":\"\",\"CPRhis\":\"无\",\"CPRnum\":\"\",\"CPRtime\":\"\",\"IDHhis\":\"无\",\"IDH100\":\"\",\"IDH80\":\"\",\"IDH50\":\"\",\"urineH\":\"11\",\"urine24H\":\"11\",\"others\":\"无\",\"otherDisease\":\"\",\"valueT\":\"1\",\"valueP\":\"1\",\"valueR\":\"1\",\"valueR1\":\"1\",\"valueR2\":\"1\",\"valueBp\":\"1\",\"height\":\"170\",\"weight\":\"60\",\"valueBMI\":\"23\",\"KidneyFuncDate\":\"2024-12-04T06:57:07.185Z\",\"KidneyFuncSCr\":\"1\",\"KidneyFuncBUN\":\"1\",\"KidneyFuncUa\":\"1\",\"liverFuncDate\":\"2024-12-04T06:57:08.661Z\",\"liverFuncAST\":\"1\",\"liverFuncALT\":\"1\",\"liverFuncTBIL\":\"1\",\"liverFuncDBIL\":\"1\",\"liverFuncALB\":\"1\",\"electrolyteDate\":\"2024-12-04T07:09:05.534Z\",\"electrolyteNa\":\"1\",\"electrolyteK\":\"1\",\"electrolyteCl\":\"1\",\"electrolyteCO\":\"1\",\"DicDate\":\"2024-12-04T07:09:06.990Z\",\"DicPT\":\"1\",\"DicAPTT\":\"1\",\"DicFIB\":\"1\",\"DicDD\":\"1\",\"CbcDate\":\"2024-12-04T07:09:08.249Z\",\"CbcHb\":\"1\",\"CbcWBC\":\"1\",\"CbcPLT\":\"1\",\"CbcCRP\":\"1\",\"UaDate\":\"2024-12-04T07:09:09.487Z\",\"UaWBC\":\"1\",\"UaRBC\":\"1\",\"UaPro\":\"1\",\"infectiousDate\":\"2024-12-04T07:09:11.531Z\",\"infectiousHBV\":\"阴性\",\"infectiousHCV\":\"阴性\",\"infectiousHIV\":\"阴性\",\"infectiousPRP\":\"阴性\",\"AboDate\":\"2024-12-04T07:09:15.005Z\",\"Abo\":\"1\",\"AboRhD\":\"阴性\",\"microbeDate\":\"2024-12-04T07:09:16.555Z\",\"microbe\":\"1\",\"imagingDate\":\"2024-12-04T07:09:17.785Z\",\"imagingLiver\":\"1\",\"imagingkidney\":\"1\",\"imagingHeart\":\"1\",\"imagingLung\":\"1\"}",
        "donate_record_json": "{\"livingWill\":true,\"relativesWill\":true,\"brainDeath\":true,\"heartDeath\":true,\"agreeState\":\"1\",\"hospital\":\"1\",\"operation\":\"1\",\"operatorDoctor\":\"1\",\"organType\":[true,true,true,true,true,true,true,true,true],\"other\":\"\",\"operaBeginDate\":\"2024-12-04T07:11:38.137Z\",\"operaBeginTime\":\"2024-12-02T09:26:47.000Z\",\"perfusionDate\":\"2024-12-18T07:11:42.573Z\",\"perfusionTime\":\"2024-12-04T07:11:47.000Z\",\"operaEndDate\":\"2024-12-11T07:11:54.502Z\",\"operaEndTime\":\"2024-12-04T07:12:47.000Z\"}",
        "start_time": int(time.time() * 1000),
        "guanzhu_time": int(time.time() * 1000),
        "death_record_json": "{\"donateType\":\"DBD\",\"brainDeath\":{\"place\":\"1\",\"clinicalBrainDeath\":{\"date\":\"2024-12-04T07:10:17.019Z\",\"time\":\"2024-12-04T07:14:12.000Z\",\"doctorFirst\":\"1\",\"doctorSecond\":\"1\",\"result\":\"符合\"},\"checkItems\":{\"eegCheck\":true,\"evoCheck\":true,\"craCheck\":true},\"eegExamination\":{\"date\":\"2024-12-04T07:10:22.505Z\",\"time\":\"2024-12-04T07:13:12.000Z\",\"result\":\"符合\"},\"evokedPotentialExamination\":{\"date\":\"2024-12-04T07:10:26.168Z\",\"time\":\"2024-12-04T08:10:12.000Z\",\"result\":\"符合\"},\"cranialDopplerUltrasound\":{\"date\":\"2024-12-04T07:10:31.224Z\",\"time\":\"2024-12-04T07:11:12.000Z\",\"result\":\"符合\"},\"spontaneousRespirationStimulationTest\":{\"date\":\"2024-12-04T07:10:34.950Z\",\"time\":\"2024-12-04T07:17:12.000Z\",\"doctorFirst\":\"1\",\"doctorSecond\":\"1\",\"result\":\"符合\"}},\"heartDeath\":{\"date\":\"\",\"time\":\"\",\"hospital\":\"\",\"heartStopMinute\":\"\",\"unrecoveredMinute\":\"\",\"deathTime\":\"\"}}"
    }

# 调用递归解析函数
parsed_payload = recursive_parse(payload)

# 打印解析后的结果，使用 json.dumps 格式化输出
print(json.dumps(parsed_payload, indent=4, ensure_ascii=False))